using Medical.Domain.DepartmentInfo;
using Medical.Domain.Enum;
using System.ComponentModel.DataAnnotations;

namespace Medical.Api.Write.Dto.DepartmentManagement
{
    /// <summary>
    /// 领用申请和物品添加请求DTO
    /// </summary>
    public class AdoptedRequestDto
    {
        /// <summary>
        /// 领用申请信息
        /// </summary>
        [Required(ErrorMessage = "领用申请数据不能为空")]
        public TouseTableDto TouseTable { get; set; }

        /// <summary>
        /// 物品列表
        /// </summary>
        public List<ItemTable> ItemTables { get; set; }
    }

    /// <summary>
    /// 领用申请DTO，用于处理日期格式问题
    /// </summary>
    public class TouseTableDto
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 物品的Id
        /// </summary>
        public int ItemId { get; set; }
        
        /// <summary>
        /// 申请单号
        /// </summary>
        public int ApplicationNumber { get; set; }
        
        /// <summary>
        /// 申请单位
        /// </summary>
        public DepartmentEnum.ApplyingUnitEnum ApplyingUnit { get; set; }
        
        /// <summary>
        /// 发放单位(供应商)
        /// </summary>
        public SupplierEnum IssuingUnit { get; set; }
        
        /// <summary>
        /// 申请时间
        /// </summary>
        public DateTime ApplicationTime { get; set; }
        
        /// <summary>
        /// 申请人
        /// </summary>
        public string Applicant { get; set; }
        
        /// <summary>
        /// 是否紧急
        /// 0:否   1:是
        /// </summary>
        public int Urgent { get; set; }
        
        /// <summary>
        /// 领用状态
        /// 1:新增  2:审核  3:接收
        /// </summary>
        public int TouseStatus {  get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
        
        /// <summary>
        /// 将DTO转换为领域实体
        /// </summary>
        public TouseTable ToEntity()
        {
            return new TouseTable
            {
                Id = this.Id,
                ItemId = this.ItemId,
                ApplicationNumber = this.ApplicationNumber,
                ApplyingUnit = this.ApplyingUnit,
                IssuingUnit = this.IssuingUnit,
                ApplicationTime = this.ApplicationTime,
                Applicant = this.Applicant,
                Urgent = this.Urgent,
                TouseStatus = this.TouseStatus,
                Remark = this.Remark,
                CreateTime = DateTime.Now, // 明确设置创建时间为当前时间
                UpdateTime = DateTime.Now  // 明确设置更新时间为当前时间
            };
        }
    }
} 